<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ArrowRight, QuestionFilled } from '@element-plus/icons-vue'

const router = useRouter()
const inputText = ref('')

// 推理模式控制
const enableReasoning = ref(false) // 默认启用推理模式

// 创建Think图标组件
const Think = {
  template: `
    <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
      <path fill="currentColor" d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"/>
      <path fill="currentColor" d="M623.6 316.7C593.6 290.4 554 276 512 276s-81.6 14.4-111.6 40.7C369.2 344 352 380.7 352 420v7.6c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V420c0-44.1 43.1-80 96-80s96 35.9 96 80c0 31.1-22 59.6-56.1 72.7-21.2 8.1-39.2 22.3-52.1 40.9-13.1 19-19.8 41.3-19.8 64.9V620c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-22.7a48.3 48.3 0 0 1 30.9-44.8c59-22.7 97.1-74.7 97.1-132.5 0-39.3-17.2-76-48.4-103.3z"/>
      <path fill="currentColor" d="M512 732a40 40 0 1 0 0 80 40 40 0 0 0 0-80z"/>
    </svg>
  `
}

const handleSend = () => {
  if (inputText.value.trim()) {
    router.push({
      path: '/query',
      query: { 
        q: inputText.value,
        reasoning: enableReasoning.value // 传递推理模式状态
      }
    })
  }
}
</script>

<template>
  <div class="home-container">
    <div class="input-section">
      <div class="input-wrapper">
        <!-- 推理选项控制栏 -->
        <div class="reasoning-control">
          <div class="control-item">
            <el-switch
              v-model="enableReasoning"
              :active-icon="Think"
              inactive-color="#dcdfe6"
              active-color="#409eff"
              size="small"
            />
            <span class="control-label">启用推理模式</span>
            <el-tooltip 
              content="开启后AI会显示思考过程，提供更详细的分析" 
              placement="top"
            >
              <el-icon class="info-icon"><QuestionFilled /></el-icon>
            </el-tooltip>
          </div>
        </div>
        
        <!-- 输入区域 -->
        <el-input
          v-model="inputText"
          type="textarea"
          :autosize="{ minRows: 1, maxRows: 7 }"
          placeholder="输入你的问题"
          class="wide-input"
          resize="none"
          @keydown.enter.ctrl="handleSend"
          @keydown.enter.meta="handleSend"
        />
        
        <!-- 操作栏 -->
        <div class="action-bar">
          <div class="action-info">
            <span class="shortcut-hint">Ctrl+Enter 发送</span>
            <span v-if="enableReasoning" class="reasoning-status">
              <el-icon><Think /></el-icon>
              推理模式
            </span>
          </div>
          <el-button 
            type="primary" 
            @click="handleSend"
            :icon="ArrowRight"
            circle
            class="send-button"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.home-container {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.input-section {
  width: 100%;
  max-width: 1000px;
  display: flex;
  justify-content: center;
}

.input-wrapper {
  width: 100%;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

/* 推理控制栏样式 */
.reasoning-control {
  padding: 12px 20px 8px 20px;
  border-bottom: 1px solid #f0f0f0;
  background: #fafafa;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 14px;
  color: #666;
  user-select: none;
}

.info-icon {
  font-size: 14px;
  color: #999;
  cursor: help;
}

/* 输入区域样式 */
.wide-input :deep(.el-textarea__inner) {
  width: 100%;
  font-size: 16px;
  padding: 16px 20px;
  border: none;
  outline: none;
  color: #333;
  resize: none;
  line-height: 1.5;
  min-height: 60px;
  background: transparent;
  box-shadow: none;
}

/* 操作栏样式 */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: #fff;
}

.action-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.shortcut-hint {
  font-size: 12px;
  color: #999;
}

.reasoning-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #409eff;
  background: #f0f9ff;
  padding: 2px 8px;
  border-radius: 12px;
}

/* 发送按钮样式 */
.send-button {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  background-color: #409EFF;
  color: white;
  border: none;
  border-radius: 50%;
}

.send-button.is-circle {
  border-radius: 50%;
  padding: 0;
}

.send-button:hover {
  background-color: #66b1ff;
}
</style>